import router from '@/router'
import { checkAuth } from './accessRole'
import { useUserStore } from '@/stores/user'

router.beforeEach((to, from, next) => {
  const userStore = useUserStore()
  // 跳过对无权限页面本身的检查
  if (to.path === '/noAuth') {
    return next()
  }
  //当前页面需要权限
  const needAccess = to.meta.access as string
  if (typeof needAccess !== 'undefined' && !checkAuth(userStore.loginUser, needAccess)) {
    return next('/noAuth')
  }

  next()
})
